package leetcode;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2483.java
 * @Author : WangRuoyu
 * @Date 2023/2/24 10:48
 */
public class Q2483 {
    public int bestClosingTime(String customers) {
        int tmp = 0;
        int time = 0;
        int minValue = tmp;

        for (int i = 0; i < customers.length(); ++i) {
            if (customers.charAt(i) == 'Y') {
                tmp -= 1;
                if (minValue > tmp) {
                    time = i + 1;
                    minValue = tmp;
                }
            } else {
                tmp += 1;
            }
        }
        return time;
    }

    public static void main(String[] args) {
        Q2483 sl = new Q2483();
        String customers = "YYNY";
        System.out.println(sl.bestClosingTime(customers));
    }
}
